<?php
header('Content-Type: application/json; charset=ISO-8859-1');
$con = mysql_connect("127.0.0.1","root","457812");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("cruzRoja", $con);

$nom = "";
$loc = "";
$txt = "Alerta Cruz Roja!";

if (isset($_GET['nom']) ) $nom = $_GET['nom'];
if (isset($_GET['loc']) ) $loc = $_GET['loc'];
if (isset($_GET['txt']) ) $txt = $_GET['txt'];


$sql = "select 
Nombre, Apellido, DomCodPos, upper(DomLocalidad) as 'DomLocalidad', DomTelefMovil, lat ,lon 
from rrhh where DomTelefMovil is not NULL AND upper(DomLocalidad)  like upper('%".$loc."%')  
and upper(Nombre) like upper('%".$nom."%') order by DomLocalidad";

$result = mysql_query($sql);
$i=0;
while($row = mysql_fetch_array($result)){
	mysql_query("INSERT INTO `cruzRoja`.`outbox` (`DestinationNumber`, `TextDecoded`) 
	VALUES ('".$row['DomTelefMovil']."', '".$txt."')");
	$i++;
}
echo '{"count":'.$i."}";
mysql_close($con);
?> 